const app = getApp();
Page({
  data: {
    money: 0,
    backurl: '/images/backimage.png',
    moneys: [{
      id: 0,
      money: 6,
      month: 1,
      bordercolor: 'grey',
      color: 'black'
    },
    {
      id: 1,
      money: 30,
      month: 5,
      bordercolor: 'grey',
      color: 'black'
    },
    {
      id: 2,
      money: 68,
      month: 12,
      bordercolor: 'grey',
      color: 'black'
    },
    {
      id: 3,
      money: 108,
      month: 18,
      bordercolor: 'grey',
      color: 'black'
    },
    {
      id: 4,
      money: 268,
      month: 45,
      bordercolor: 'grey',
      color: 'black'
    },
    {
      id: 5,
      money: 698,
      month: 120,
      bordercolor: 'grey',
      color: 'black'
    }
    ],
    cmoney: 0,
    id: ''
  },
  changecolor: function (e) {
    // var Index = e.currentTarget.dataset.index;
    var moneys = this.data.moneys;
    var id = e.currentTarget.id;
    var that = this;
    for (var i = 0; i < 6; i++) {
      if (i == id) {
        moneys[id].color = '#fcd925';
        moneys[id].bordercolor = '#fcd925';
      }
      else {
        moneys[i].color = 'black';
        moneys[i].bordercolor = 'grey';
      }

    }
    moneys[id].color = '#d0312b';
    moneys[id].bordercolor = '#d0312b';
    that.setData({
      money: moneys[id].money,
      moneys: moneys
    });
  },

  onLoad: function (options) {

  },

  chongzhi: function () {
    var money = this.data.money;
    console.log("money:" + money + " openid:" + app.globalData.openid)
    var that = this;

    wx.request({
      url: app.globalData.headurl + '/qcustomer/updateCustomerByMoney',
      data: {
        openid: app.globalData.openid,
        money: money
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
        //token: app.globalData.token
      },
      success: function (r) {
        app.globalData.customer=r.data;
        wx.showToast({
          title: '充值成功',
        })
        wx.navigateBack({})
      }
    })


  },


})